/*
 * miniFreeRTOS SOC System emulation.
 *
 * Copyright (c) 2024- yanl1229@163.com.
 * Written by yanl1229
 *
 * This code is licensed under the GPL.
 */
#ifndef MUTEX_H
#define MUTEX_H

#include "list.h"
#include "task.h"

/*
 * 互斥锁管理结构
 */
struct mutex
{
    struct list_head waiter_list;           /* 等待互斥锁释放任务列表 */
    struct task_struct *owner;              /* 互斥锁的持有者 */
    volatile uint32_t count;                /* 计数器 */
};


/*
 * 创建互斥锁
 */
extern struct mutex * mutex_create();

/**
 * 删除互斥锁
 */
extern void mutex_delete(struct mutex *lock);
/**
 * 释放互斥锁
 */
extern uint32_t  mutex_unlock(struct mutex * lock);
/**
 * 获取互斥锁
 */
extern uint32_t mutex_lock(struct mutex * lock, uint32_t wait_ticks);

#endif